const { promisify } = require('util');
const figlet = promisify(require('figlet'))
const clear = require('clear')
const chalk = require('chalk');
const { clone } = require('./download');
const path = require('path')
const fs = require('fs')
const process = require('child_process')

const log = content => console.log(chalk(content))

module.exports = async (name) => {
    // 打印欢迎界面
    clear()
    const data = await figlet(name)
    log(data)
    try {
        const dir = fs.statSync(path.join(__dirname, '../' + name));
        console.log('----' + dir)
        log('目录已存在')
        //清空指定文件夹下文件
        process.exec('rm -fr ' + path.join(__dirname, '../' + name), async (err) => {
            if (!err) {
                log(`🚀 创建项目 ${name}`)
                // await clone('github:JackySoft/vue3.0-demo',name)
                // await clone('direct:git@gitlab.2345.cn:ued/business/ssp.2345.cn.git', name)
                // await clone('direct:ssh://git@git.imooc.com:80/coding-502/manager-fe.git', name)
                await clone('direct:https://github.com/JackySoft/vue3.0-demo.git', name)
            }
        })
    } catch (error) {
        log(`🚀 创建项目 ${name}`)
        // 下载仓库地址
        // 直接下载https地址
        // await clone('direct:https://gitee.com/jack-bean/test.git', name)
        await clone('JackySoft/vue3.0-demo', name)

        // await clone('direct:https://git.imooc.com/coding-502/manager-fe.git', name)
    }
} 